/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.Random;
import java.util.concurrent.TimeUnit;

/**
 * <p>Project: javase - Ex2
 * <p>Powered by webrx On 2021-12-27 09:37:56
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Ex2 {
    synchronized void m1() {
        String t = Thread.currentThread().getName();
        System.out.println(t + "线程启动");
        Random rand = new Random();
        while (true) {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (Exception e) {
                e.printStackTrace();
            }
            int a = rand.nextInt(10);
            int b = rand.nextInt(10);
            try {
                int c = a / b;
            } catch (Exception e) {
                break;
            }

        }

    }

    void m2() {
        String t = Thread.currentThread().getName();
        System.out.println(t + "线程启动");
    }

    synchronized void m3() {
        String t = Thread.currentThread().getName();
        System.out.println(t + "线程启动");
    }

    public static void main(String[] args) {
        var t = new Ex2();
        new Thread(t::m1, "A").start();
        new Thread(t::m2, "B").start();
        new Thread(t::m3, "C").start();
    }
}
